﻿using AutoMapper;
using Common.Damin;
using Common.Infrastructrue;
using Common.Infrastructrue.Interface;
using Common.Service;
using MediatR;
using RabitPart.WritedPartApi.Application.Comman.RBACfile;
using System.Data;

namespace RabitPart.WritedPartApi.Application.CommanHandel.RBACfile
{
    public class RBACRel_User_RoleCreateCommanHandel : IRequestHandler<RBACRel_User_RoleCreateComman, ApiResult>
    {
        private readonly IRel_user_roleResponstity useroleRE;
        private readonly ILogger<RBACRel_User_RoleCreateCommanHandel> logger;
        private readonly IMapper mapper;
        public RBACRel_User_RoleCreateCommanHandel(IRel_user_roleResponstity useroleRE, ILogger<RBACRel_User_RoleCreateCommanHandel> logger, IMapper mapper)
        {
            this.useroleRE = useroleRE;
            this.logger = logger;
            this.mapper = mapper;
        }

        public Task<ApiResult> Handle(RBACRel_User_RoleCreateComman request, CancellationToken cancellationToken)
        {
            var useroleadd = mapper.Map<Rel_user_role>(request);
            useroleadd.CreateDate = DateTime.Now;
            useroleadd.CreateOperatorName = "用户角色添加";
            useroleRE.InsertAsync(useroleadd);
            return Task.FromResult(ApiResult.Success(StatusCodeEnum.Ok));
        }
    }
}
